package cn.yujiago.miaosha.mapper;

import cn.yujiago.miaosha.entity.MiaoshaOrder;
import cn.yujiago.miaosha.entity.Order;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderMapper {

    @Select("SELECT * FROM miaosha_order WHERE user_id = #{userId} AND goods_id = #{goodsId}")
    MiaoshaOrder selectMiaoshaOrderByUIDAndGID(@Param("userId") Long userId, @Param("goodsId") Long goodsId);

    @Insert("INSERT INTO `order`(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date) VALUES(#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel}, #{status}, #{createDate})")
    @SelectKey(keyProperty="id", resultType=long.class, before=false, statement="select last_insert_id()")
    long insert(Order order);

    @Insert("insert into miaosha_order(user_id, goods_id, order_id) values(#{userId}, #{goodsId}, #{orderId})")
    long insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);

    @Select("SELECT * FROM `order` WHERE id = #{id}")
    Order selectOrderById(@Param("id") Long orderId);
}
